package io.itit.ecp.admin.provide.renderer;

import io.itit.ecp.admin.server.entity.CarbonEmissionRangeEntity;
import io.itit.ecp.admin.server.service.ICarbonEmissionRangeService;
import io.itit.grass.estelle.starter.parse.AbstractParseRenderer;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Scope("prototype")
@Component(KCarbonEmissionRangeRenderer.ENTITY_NAME)
public class KCarbonEmissionRangeRenderer extends AbstractParseRenderer<CarbonEmissionRangeEntity> {

    public static final String ENTITY_NAME = "KCarbonEmissionRangeRenderer";

    @Resource
    private ICarbonEmissionRangeService carbonEmissionRangeService;

    @Override
    public String entityName() {
        return ENTITY_NAME;
    }

    @Override
    public int getHeadRowIndex() {
        return 1;
    }

    @Override
    public Class<CarbonEmissionRangeEntity> getClazz() {
        return CarbonEmissionRangeEntity.class;
    }

    @Override
    public int processAfter(List<CarbonEmissionRangeEntity> resultList) {
        if (CollectionUtils.isEmpty(resultList)) {
            return 0;
        }
        carbonEmissionRangeService.saveBatch(resultList);
        return resultList.size();
    }
}
